import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', () => {
  const user = ref({})
  const theme = ref({
    asideBg: '#ECF1F4',
    asideText: '#000',
    headerBg: '#ECF1F4',
    headerText: '#000'
  })

  const setTheme = (data) => {
    theme.value = data
  }
  const login = (data) => {
    user.value = data
  }
  const logout = () => {
    user.value = {}
  }
  const isLogin = computed(() => {
    return user.value.token
  })
  return { user, isLogin, login, logout, theme, setTheme }
},
  {
    persist: {
      key: 'user',
      storage: localStorage
    }
  }
)